<%-- 
    Document   : index
    Created on : Sep 15, 2011, 8:22:27 AM
    Author     : Arturia
--%>

<%@page import="java.io.InputStream"%>
<%@page import="java.util.Properties"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Book detail</title>
        <link href="css/style.css" rel="stylesheet" type="text/css"/>
        <link href="css/bannerstyle.css" rel="stylesheet" type="text/css"/>
        <link href="css/TableCSS.css" rel="stylesheet" type="text/css"/>
        <link href="css/thumbnail_css.css" rel="stylesheet" type="text/css"/>

        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<script type="text/javascript">
            function setVisibility(showUser, isAdmin){
                if(showUser == "true"){
                    document.getElementById("user").style.visibility = "visible";
                    document.getElementById("loggeduser").style.visibility = "hidden";
                }else if(showUser == "false" && isAdmin == "true"){
                    document.getElementById("loggeduser").style.visibility = "visible";
                    document.getElementById("user").style.visibility = "hidden";
                    document.getElementById("user_link").textContent = "| Admin";
                    document.getElementById("user_link").href = "admin.jsp";
                    document.getElementById("quantity").style.visibility = "hidden";
                    document.getElementById("addcartbutton").style.visibility = "hidden";
                }else if(showUser == "false" && isAdmin == "false"){
                    document.getElementById("loggeduser").style.visibility = "visible";
                    document.getElementById("user").style.visibility = "hidden";
                    document.getElementById("user_link").textContent = "| View Cart";
                    document.getElementById("user_link").href = "viewcart.jsp";
                    document.getElementById("quantity").style.visibility = "visible";
                    document.getElementById("addcartbutton").style.visibility = "visible";
                }
            }

            function checkSearch(){
                if (document.getElementById("searchText").value.toString().length == 0){
                    alert("Must input somrthing!")
                    return false;
                }else{
                    return true;
                }
            }
        </script>
        <%
                    //check and set username
                    String loggedUser = (String) session.getAttribute("USER");
                    String showUser = "";
                    String isAdmin = "";
                    if (loggedUser == null) {
                        showUser = "true";
                    } else {
                        showUser = "false";
                        isAdmin = (String) session.getAttribute("ISADMIN");
                        if (isAdmin == null || isAdmin == "false") {
                            isAdmin = "false";
                        } else {
                            isAdmin = "true";
                        }
                    }
        %>
    </head>
    <body onload='setVisibility("<%=showUser%>", "<%=isAdmin%>")'>
        <c:set var="doc" value="${sessionScope.doc}" />
        <c:set var="bookID" value="${param.bookID}" />
        <x:set var="selectedBook" select="$doc//*[bookID=$bookID]" />
        <div id="header-wrap">
            <div id="header">
                <div style="margin:0px; text-align: left; float: left;"> <span style="color: #FFFFFF; font-family:'Arial Black',Gadget,sans-serif; font-size: 20px; font-weight: bold; letter-spacing: -2px;"><a href="index.jsp" style="color: #FFF; text-decoration: none;" title="Awesomebooks.com">AWESOMEBOOKS</a></span> <a style="color: #FFF; font-size: 18px; font-family: Georgia, 'Times New Roman', Times, serif; font-style:italic; font-weight:normal; text-decoration: none;" href="index.jsp" title="Find your own book">Find your own book</a> 	</div>
                <ul class="menu">

                    <!-- Begin Simple Item Without Drop -->
                    <li class="">
                        <a href="newrelease.jsp">New Release</a>
                    </li>
                    <li class="">
                        <a href="bestseller.jsp">Best Seller</a>
                    </li>
                    <li class="">
                        <a href="bookreview.jsp">Books Review</a>
                    </li>

                    <li class="drop">
                        <a href="#">Catalogs</a>
                        <span class="toggle">&nbsp;</span>
                        <ul>
                            <li><a href="Controller?Action=Search&searchText=literature&Category=true">Literature</a></li>
                            <li><a href="Controller?Action=Search&searchText=life style&Category=true">Life Style</a></li>
                            <li><a href="Controller?Action=Search&searchText=tutorial&Category=true">Tutorial</a></li>
                            <li><a href="Controller?Action=Search&searchText=discovery&Category=true">Discovery</a></li>
                            <li><a href="Controller?Action=Search&searchText=science&Category=true">Science</a></li>
                            <li><a href="Controller?Action=Search&searchText=kids&Category=true">Kids</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <div id="underheader">
                <form action="Controller" onsubmit="return checkSearch()" method="POST">
                    <span id="searchbox" style="width:50%">
                        <input id="searchText" name="searchText" type="text" style="width:250px; border:1px solid #333333" />
                        <input name="Action" type="submit" value="Search" id="button" />
                    </span>
                    <span id="user" style="width:50%">
                        <a href="login.jsp">Login</a> |
                        <a href="register.jsp">Register</a>
                    </span>
                    <span id="loggeduser" style="width:50%;position: relative; left: -180px; visibility: hidden">
                        <a><%=loggedUser%></a>
                        <a href="Controller?Action=Logout">(Logout)</a>
                        <a id="user_link" href="viewcart.jsp">| View Cart</a>
                    </span>
                </form>
            </div>
        </div>
        <center>


            <div id="content-header" style="height: 50px">
                <ul>
                    <a>Book detail</a>
                </ul>
            </div>
            <form id="content" action="Controller" style="position: relative; left: 0px">
                <table style="width: 800px">
                    <tr>
                        <td colspan="1" style="width: 30%">
                            <div class="gallerycontainer">
                                <a class="thumbnail" href="#thumb">
                                    <img src="covers/<x:out select="$selectedBook//imageLink" />" width="130px" border="0" />
                                    <span><img src="covers/<x:out select="$selectedBook//imageLink" />" width="300px" /><br /> <x:out select="$selectedBook//title" /></span></a>
                            </div>
                        </td>
                        <td colspan="2" style="border-left:1px #FFF solid; width: 70%">
                            <div id="bookdetail">
                                <ul>
                                    <input type="hidden" name="bookID" value="${bookID}" />
                                    <li>[Title] <x:out select="$selectedBook//title" /></li>
                                    <li>[Author]<x:out select="$selectedBook//author" /></li>
                                    <li>[Price]<x:out select="$selectedBook//price" /></li>
                                    <li>[Publisher]<x:out select="$selectedBook//publisher" /></li>
                                    <li>[Status]
                                        <x:if var="status" select="$selectedBook//inventory>0">
                                            <c:out value="Available" />
                                        </x:if>
                                        <x:if var="status" select="$selectedBook//inventory<=0">
                                            <c:out value="Out of stock" />
                                        </x:if>
                                    </li>
                                    <select id="quantity" name="quantity">
                                        <option>1</option>
                                        <option>2</option>
                                        <option>3</option>
                                        <option>4</option>
                                        <option>5</option>
                                        <option>6</option>
                                        <option>7</option>
                                        <option>8</option>
                                        <option>9</option>
                                        <option>10</option>
                                    </select>
                                    <button id ="addcartbutton" name="Action" value="AddCart" type="submit" >Add to cart</button>

                                </ul>
                            </div>
                        </td>

                    </tr>
                    <tr>
                        <td colspan="3" style="border-top:1px #FFF solid">
                                <div id="bookdetailTitle">Description:</div>
                                <div id="description">
                            <x:out select="$selectedBook//description" /></div>
                        </td>
                    </tr>
                </table>
            </form>
        </center>
    </body>
</html>
